import android.annotation.SuppressLint
import android.content.Context
import android.net.ConnectivityManager

/**
 *decs 网络工具类
 *auther mkk
 *time  17:25
 *date  2021/11/19  17:25
 **/
class NetworkUtils {
    @SuppressLint("MissingPermission")
    fun isConnected(context: Context): Boolean {
        var connectivity =
            context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        if (null != connectivity) {
            try {
                val info = connectivity.activeNetworkInfo
                if (null != info && info.isConnected) {
                    return true
                }
            } catch (e: Exception) {
                e.printStackTrace()
                //如果因为权限问题抛出异常, 这里正常返回
                return true
            }
        }
        return false
    }
}